﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace suanfa
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] ss = { 5, 2, 1, 4, 12 };
            maopao(ss);
            // TestDigui();
            Console.ReadKey();
        }


        /// <summary>
        /// 冒泡
        /// </summary>
        public static void maopao(int[] arrylist)
        {
            //[2,3,5,1,6]
            int tempValue ;
            for (int i = 0; i <= arrylist.Length - 1; i++)
            {
                for (int j = arrylist.Length - 1; j > i; j--)
                {
                    if (arrylist[j] < arrylist[j - 1])
                    {
                        tempValue = arrylist[j];
                        arrylist[j] = arrylist[j - 1];
                        arrylist[j - 1] = tempValue;
                    }
                }
            }

            var sss = arrylist.ToList();
            sss.ForEach((x) => {
                Console.WriteLine(x.ToString());
            });  

        }


        public static void TestDigui()
        {
            DiguiModel diguiModel1 = new DiguiModel() { Name = "子节点三", Child = null };
            List<DiguiModel> list = new List<DiguiModel>() { new DiguiModel() { Name="子节点1" , Child = null},
                new DiguiModel() { Name = "子节点二", Child = new List<DiguiModel>(){ diguiModel1 } } };
            DiguiModel diguiModel = new DiguiModel() { Name="根节点", Child = list };
            diguit(diguiModel);
        }



        //递归
        public static void  diguit(DiguiModel digui)
        {

            Console.WriteLine($"打印{digui.Name}");
            if (digui.Child != null)
            {
                digui.Child.ForEach((x) =>
                {
                    diguit(x);
                });
            }
        }


    }
}
